package com.leetcode.array;

import java.util.Arrays;
import java.util.TreeMap;

public class SumImbalanceNumbers {
    public static void main(String[] args) {

    }

    public int sumImbalanceNumbers(int[] nums) {
        int res = 0;
        int n = nums.length;
        boolean[] visited = new boolean[n + 1];
        for (int i = 0; i < n - 1; i++) {
            Arrays.fill(visited, false);
            visited[nums[i]] = true;
            int cnt = 0;
            for (int j = i + 1; j < n; j++) {
                int val = nums[j];
                if (!visited[val]) {
                    cnt++;
                    if (visited[val - 1]) {
                        cnt--;
                    }
                    if (visited[val + 1]) {
                        cnt--;
                    }
                    visited[val] = true;
                }
            }
            res += cnt;
        }
        return res;
    }
}
